#!/usr/bin/env python
# vim:fileencoding=utf-8

from calibre.web.feeds.news import BasicNewsRecipe


class Grani(BasicNewsRecipe):
    title = '\u0413\u0440\u0430\u043D\u0438.\u0420\u0443'
    __author__ = 'bugmen00t'
    description = '\u0415\u0436\u0435\u0434\u043D\u0435\u0432\u043D\u0430\u044F \u0438\u043D\u0442\u0435\u0440\u043D\u0435\u0442-\u0433\u0430\u0437\u0435\u0442\u0430. \u041E\u0431\u0437\u043E\u0440\u044B \u0438 \u0430\u043D\u0430\u043B\u0438\u0437 \u0440\u043E\u0441\u0441\u0438\u0439\u0441\u043A\u0438\u0445 \u0438 \u043C\u0438\u0440\u043E\u0432\u044B\u0445 \u043F\u043E\u043B\u0438\u0442\u0438\u0447\u0435\u0441\u043A\u0438\u0445 \u0441\u043E\u0431\u044B\u0442\u0438\u0439, \u0441\u0442\u0430\u0442\u044C\u0438 \u0438 \u0432\u0438\u0434\u0435\u043E \u043E \u043F\u043E\u043B\u0438\u0442\u0438\u0447\u0435\u0441\u043A\u0438\u0445 \u0437\u0430\u043A\u043B\u044E\u0447\u0451\u043D\u043D\u044B\u0445.'  # noqa
    publisher = '\u041E\u041E\u041E "\u0424\u043B\u0430\u0432\u0443\u0441"'
    category = 'newspaper'
    cover_url = u'https://graniru.org/files/96172.png'
    language = 'ru'
    no_stylesheets = False
    remove_javascript = False
    auto_cleanup = False
    remove_empty_feeds = True
    oldest_article = 30
    max_articles_per_feed = 50

    remove_tags_before = dict(name='h3')

    remove_tags_after = dict(name='div', attrs={'class': 'main-text clearfix'}),

    # Original feeds
    #    feeds = [
    #        ('\u0412\u0441\u0435 \u043C\u0430\u0442\u0435\u0440\u0438\u0430\u043B\u044B', 'https://graniru.org/export/all-atom.xml'),
    #        ('\u0421\u0442\u0430\u0442\u044C\u0438', 'https://graniru.org/export/articles-atom.xml')
    #        ]

    # Feeds from mirror site
    feeds = [
        (
            '\u0412\u0441\u0435 \u043C\u0430\u0442\u0435\u0440\u0438\u0430\u043B\u044B',
            'https://grani2.appspot.com/export/all-atom.xml'
        ),
        (
            '\u0421\u0442\u0430\u0442\u044C\u0438',
            'https://grani2.appspot.com/export/articles-atom.xml'
        ),
    ]

    # Mirror site feeds transformation
    def print_version(self, url):
        return url.replace('https://graniru.org/', 'https://grani2.appspot.com/')
